Product : ISaGRAF V3.23
Date : 1-October-1998
File : NulInMsg.Managing C Function or C FBloc that use messages
with null character.htm
Subject : Managing C Function or C Function Block that use messages
with null character
Keywords: C function - C function block - null character - message
string
____________________________________________________________________
Question:
If it possible to manage messages that include 0 (NULL) character?
Answer:
Yes, it’s possible since 3.23 release of ISaGRAF kernel.
Here below is described the behavior of ISaGRAF kernel
before 3.23 release:
All ISaGRAF C functions, created on the workbench by using the library
and then modified and linked to an ISaGRAF kernel, have following
particularity:
1st character of the message located inside the kernel data-base
(the function receives MESSAGE, with variable type T_MSG = char*)
But if that received pointer MESSAGE is decreased (-1), it’s then possible
to obtain current length of the application variable
(declared in ISaGRAF dictionary) used as an input parameter.
a temporary buffer with maximum size (=255 or 256).
When the content of the temporary buffer is copied into a variable
(= one that has been declared inside the dictionary), then
if the variable maximum length (the length allocated inside the dictionary)
isn’t large enough to contain what is in the temporary buffer, only a part
of the temporary buffer is copied into the output variable
What has been changed in ISaGRAF since 3.23 release, is that the kernel has been
modified and C function calling mechanism has been enhanced.
One of the kernel modification consists in allocating 3 additional characters,
for each temporary buffer allocated for copying in it the result of a function
(result with message type only).
The first allocated character (called USE_CL on schema here below) is a flag that
indicates if yes or no the function has set a valid value into the
« Current Length » character. This flag has to be set by the C function itself.
The second allocated character is maximum length.
The third allocated character has to be filled by the function itself, and contains
the current length of the message output parameter.
Examples of C function block using messages with null characters:
Example 1:
The following C function returns a message variable that is made only of
3 NULL characters.
Function input parameter : none
Function output parameter : variable Q with message type
void USP_null3msg (str_arg *arg)
{
char* p_UseCL = Q-3 ;
Q[0]=0;
Q[1]=0;
Q[2]=0;
Q[3] = '\0'; /* Null character again. */
/*This is just to remind returned string needs to be ended by Null character */
/* strores string current length to 3 */
p_UseCL[2] = 3;
/* Indicates that current length has been changed by setting USE_CL flag */
p_UseCL[0] = 1;
}
Example 2:
The following C function returns the current length of a message variable that
may include NULL character inside.
Function input parameter : msg_wn with ‘message’ type
Function output parameter : length with ‘integer’ type
void ISADLL USP_len_wn (str_arg *arg)
{
arg->length = (int32) (*((arg->msg_wn) -1));
}
____________________________________________________________________
Copyright © 1996-2009 ICS Triplex ISaGRAF Inc. All rights reserved.